package com.google.code.retrobox.editor.commons;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.util.LinkedList;
import java.util.List;

import javax.swing.BorderFactory;
import javax.swing.JPanel;
import javax.swing.border.BevelBorder;

public class ColorButton extends JPanel {
	/**
	 * 
	 */
	private ColorButton self = this;
	
	private static final long serialVersionUID = 1L;
	private List<ActionListener> listeners = new LinkedList<ActionListener>();
	private boolean mouseInside = false;
	
	public ColorButton() {
		super();
		
		addMouseListener(new MouseListener() {

			public void mouseClicked(MouseEvent e) {
				
			}

			public void mouseEntered(MouseEvent e) {
				mouseInside = true;
				setBorder(BorderFactory.createBevelBorder(BevelBorder.RAISED));
			}

			public void mouseExited(MouseEvent e) {
				mouseInside = false;
				setBorder(null);
			}

			public void mousePressed(MouseEvent e) {
				
			}

			public void mouseReleased(MouseEvent e) {
				if (mouseInside) {
					for (ActionListener element: listeners) {
						element.actionPerformed(new ActionEvent(self, 1, "Mouse clicked"));
					}
				}
			}
			
		});
	}
	
	public void addActionListener(ActionListener listener) {
		listeners.add(listener);
	}
}